package com.lds.offer.demo;

import java.util.Arrays;

/**
 * @description: Offer 17. 打印从1到最大的n位数
 * @author: lds
 * @create: 2022-10-11 17:16
 **/
public class Offer_17_打印从1到最大的n位数 {

    //https://leetcode.cn/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/

    /**
     * 第一念头是先根据n，拼接到n个9，再循环打印
     * 但是改方法不适合大数情况，大数具体方法需要在思考一下
     */

    public static void main(String[] args) {
        int[] print = print(1);
        int[] print2 = print2(1);
        System.out.println(Arrays.toString(print));
        System.out.println(Arrays.toString(print2));
    }

    public static int[] print(int n) {

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            builder.append(9);
        }
        Integer integer = Integer.valueOf(builder.toString());
        int[] arr = new int[integer];
        for (Integer i = 0; i < integer; i++) {
            arr[i] = i+1;
        }
        return arr;
    }

    public static int[] print2(int n) {

        int integer = (int) Math.pow(10,n) -1;
        int[] arr = new int[integer];
        for (Integer i = 0; i < integer; i++) {
            arr[i] = i+1;
        }
        return arr;
    }
}
